package com.kaibes.web.api;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.kaibes.core.base.util.StringUtils;

@SuppressWarnings("serial")
@JsonInclude(Include.NON_NULL)
public class MyPage<T> extends Page<T> {

    @TableId
    private String search;

    public String getSearch() {
        return search;
    }

    public void setSearch(String search) {
        if (search != null) {
            this.search = search.trim();
        }
    }
    
    public Wrapper<T> like(String column) {
        QueryWrapper<T> wrapper = Wrappers.query();
        if (StringUtils.isNotBlank(search)) {
            wrapper.like(column, search);
        }
        return wrapper;
    }
    
    public Wrapper<T> likeLeft(String column) {
        QueryWrapper<T> wrapper = Wrappers.query();
        if (StringUtils.isNotBlank(search)) {
            wrapper.likeLeft(column, search);
        }
        return wrapper;
    }
    
    public Wrapper<T> likeRight(String column) {
        QueryWrapper<T> wrapper = Wrappers.query();
        if (StringUtils.isNotBlank(search)) {
            wrapper.likeRight(column, search);
        }
        return wrapper;
    }
    
}
